<?php
require_once 'assets/tool/PHPExcel/PHPExcel.php';
require_once 'assets/tool/PHPExcel/PHPExcel/IOFactory.php';

class stringLogic
{
    //Init properties
    protected $properties;

    /** __construct ========================
     * @author TuanNguyen
     * @desc   set param of class to default
     *         use wizard of PHP
     * =====================================*/
    function __construct()
    {
        $this->properties = array();
    }

    /** __get =================================
     * @author TuanNguyen
     * @desc   get value of properties of class
     *         use wizard of PHP method
     * ========================================*/
    function __get($propety)
    {
        return $this->properties[$propety];        
    }

    /** __set =================================
     * @author TuanNguyen
     * @desc   set value of properties of class
     *         use wizard of PHP method
     * ========================================*/
    function __set($property, $value)
    {
        $this->properties[$property] = $value;
    }


    /**
     * Convert Vietnamese letters into alphabet
     *
     * @author  TuanNguyen
     * @version Created 2015-02-08
     * @param   string $s_convertedString
     *          string to convert
     * @return  string
     */
    public static function convertVNToAlphabet($s_convertedString)
    {
        //Lower Case
        $s_convertedString = preg_replace("/(à|á|ạ|ả|ã|â|ầ|ấ|ậ|ẩ|ẫ|ă|ằ|ắ|ặ|ẳ|ẵ)/i", 'a', $s_convertedString);
        $s_convertedString = preg_replace("/(è|é|ẹ|ẻ|ẽ|ê|ề|ế|ệ|ể|ễ)/i", 'e', $s_convertedString);
        $s_convertedString = preg_replace("/(ì|í|ị|ỉ|ĩ)/i", 'i', $s_convertedString);
        $s_convertedString = preg_replace("/(ò|ó|ọ|ỏ|õ|ô|ồ|ố|ộ|ổ|ỗ|ơ|ờ|ớ|ợ|ở|ỡ)/i", 'o', $s_convertedString);
        $s_convertedString = preg_replace("/(ù|ú|ụ|ủ|ũ|ư|ừ|ứ|ự|ử|ữ)/i", 'u', $s_convertedString);
        $s_convertedString = preg_replace("/(ỳ|ý|ỵ|ỷ|ỹ)/i", 'y', $s_convertedString);
        $s_convertedString = preg_replace("/(đ)/i", 'd', $s_convertedString);

        //Upper Case
        $s_convertedString = preg_replace("/(À|Á|Ạ|Ả|Ã|Â|Ầ|Ấ|Ậ|Ẩ|Ẫ|Ă|Ằ|Ắ|Ặ|Ẳ|Ẵ)/", 'A', $s_convertedString);
        $s_convertedString = preg_replace("/(È|É|Ẹ|Ẻ|Ẽ|Ê|Ề|Ế|Ệ|Ể|Ễ)/", 'E', $s_convertedString);
        $s_convertedString = preg_replace("/(Ì|Í|Ị|Ỉ|Ĩ)/", 'I', $s_convertedString);
        $s_convertedString = preg_replace("/(Ò|Ó|Ọ|Ỏ|Õ|Ô|Ồ|Ố|Ộ|Ổ|Ỗ|Ơ|Ờ|Ớ|Ợ|Ở|Ỡ)/", 'O', $s_convertedString);
        $s_convertedString = preg_replace("/(Ù|Ú|Ụ|Ủ|Ũ|Ư|Ừ|Ứ|Ự|Ử|Ữ)/", 'U', $s_convertedString);
        $s_convertedString = preg_replace("/(Ỳ|Ý|Ỵ|Ỷ|Ỹ)/", 'Y', $s_convertedString);
        $s_convertedString = preg_replace("/(Đ)/", 'D', $s_convertedString);

        return $s_convertedString;
    }//End convertVNToAlphabet


    /**
     * Check string is not null and empty
     *
     * @author  TuanNguyen
     * @version Created 2015-02-08
     * @param   string $s_string
     *          string to check
     * @return  boolean
     */
    public static function isString($s_string)
    {
        //Check null
        if ( $s_string === null ) {
            return false;
        }

        //Check empty string
        if ( trim($s_string) === '' ) {
            return false;
        }

        return true;
    }

    /**
     * trim spaces (2 bytes, 1 bytes) of string
     *
     * @author  TuanNguyen
     * @version Created 2015-02-09
     * @param   string $s_string
     *          string to trim
     * @return  string
     */
    public static function trimSpaces($s_string)
    {
        return mb_ereg_replace('^[[:space:]　]*([\s\S]*?)[[:space:]　]*$', '\1', $s_string);
    }//End trimSpaces
}